<?php
class AddnewsAction extends BaseAction{
    public function index(){
        $this->display();
    }
    public function addnews(){
       /*  $title = $_POST["title"];
        $typeId = $_POST["typeId"];
        $writer = $_POST["writer"];
        $source = $_POST["source"];
      
        $content = $_POST["content"];
        $userName = $_SESSION["userMsg"]["userName"];
        $myFile=$_FILES['myFile'];
      var_dump($myFile);
        if($myFile['name']!=null){
            date_default_timezone_set('PRC');
           $fileName = $myFile["name"];//原文件名
			$index = strrpos($fileName,".");//找寻最后一个点的位置
			$ext = substr($fileName,$index);//扩展名
			$newName = md5(time().rand(0,9).rand(0,9).rand(0,9)).$ext;//文件保存的文件名
			$savePath = "newspicture/{$newName}";
			move_uploaded_file($myFile["tmp_name"],"./public/newspicture/$newName");
		
			$sql = "insert into newsArticles(content,title,typeId,userName,writer,source,imagepath)values('{$content}','{$title}',{$typeId},'{$userName}','{$writer}','{$source}','{$savePath}')";           
            $result=M()->execute($sql);
          
        }else{
            $result=M('newsarticles')->add($_POST);
        }
        if($result>0){
            $this->success('添加新闻成功',__APP__."/Addnews/index.html");
        }else{
            $this->success('添加新闻失败',__APP__."/Addnews/index.html");
        }*/
        import("ORG.Net.UploadFile");
        $upload=new UploadFile();
       /*  echo "<pre>";
        var_dump($upload);
        echo "</pre>"; */
        $upload->maxSize=1000000;//字节b
        $upload->allowExts=array('jpeg','jpg','gif','png');
        $upload->savePath='./public/newspicture/';
      
        if($upload->upload()){          
            $arr=$upload->getUploadFileInfo();          
        }else{
            $this->success($upload->getErrorMsg());
            exit;
        } 
       /*  echo '<pre>';
        var_dump($arr);
        echo '</pre>'; */
        $filename=$arr[0]['savename'];
        if($filename!=null){
            $title = $_POST["title"];
            $typeId = $_POST["typeId"];
            $writer = $_POST["writer"];
            $source = $_POST["source"];
            $content = $_POST["content"];
            $userName = $_SESSION["userMsg"]["userName"];
            $savePath = "newspicture/{$filename}";
            $sql = "insert into newsArticles(content,title,typeId,userName,writer,source,imagepath)values('{$content}','{$title}',{$typeId},'{$userName}','{$writer}','{$source}','{$savePath}')";
            $result=M()->execute($sql);
        }else{
            $result=M('newsarticles')->add($_POST);
        }
        if($result>0){
            $this->success('添加新闻成功',__APP__."/Addnews/index.html");
        }else{
            $this->success('添加新闻失败',__APP__."/Addnews/index.html");
        }
    } 
}












